<template>
  <div class="d_main">
    <div class="case">
      <na-table :datas.sync="tableData" :searchObj.sync="search" @updateDatas="getAllMaterils" @newAdd="newAddClick">
      </na-table>
      <SelectSCorder :per-visible.sync="showOrder" @current="selectCurrentRow" />
    </div>
    <!-- 表格操作区 E-->
    <!--table板块-->
    <!-- <div ref="tableCon" class="tableCon expandBox">
      <el-table
        v-show="tableHead.length > 0"
        id="emtable"
        ref="multipleTable"
        v-loading="searchLoading"
        :data="allMaterirls"
        :height="tableHeight || 'auto'"
        border
        fit
        style="width: 100%"
        @header-dragend="surverWidth"
      >
        <template v-for="(fruit, index) in tableHead">
          <el-table-column
            v-if="fruit.visible"
            :key="index"
            :label="fruit.columnName"
            :min-width="fruit.columnWidth || 90"
            :prop="fruit.columnCode"
            show-overflow-tooltip
            :fixed="fruit.isFloat ? 'left' : false"
          >
            <template slot-scope="scope">
              <el-button v-if="fruit.columnCode === 'getProductBillNo'" type="text" @click="checkProductList(scope.row)"> {{ scope.row[fruit.columnCode] }}</el-button>
              <div v-else-if="fruit.columnCode==='getProductBillStateName'" class="flex">
                <template v-if="scope.row.getProductBillState===0">
                  <span class="mr5 spot" style="background: #3F61F1" />{{ scope.row[fruit.columnCode] }}
                </template>
                <template v-else-if="scope.row.getProductBillState===1 || scope.row.getProductBillState===3">
                  <span class="mr5 spot" style="background: #67C23A" />{{ scope.row[fruit.columnCode] }}
                </template>
                <template v-else>
                  <span class="mr5 spot" style="background: #999AAA" />{{ scope.row[fruit.columnCode] }}
                </template>
              </div>
              <div v-else-if="fruit.columnCode==='outStockStateName'" class="flex">
                <template v-if="scope.row.outStockState===0">
                  <span class="mr5 spot" style="background: #3F61F1" />{{ scope.row[fruit.columnCode] }}
                </template>
                <template v-else-if="scope.row.outStockState===1">
                  <span class="mr5 spot" style="background: #67C23A" />{{ scope.row[fruit.columnCode] }}
                </template>
                <template v-else>
                  <span class="mr5 spot" style="background: #E13335" />{{ scope.row[fruit.columnCode] }}
                </template>
              </div>
              <template v-else>
                {{ scope.row[fruit.columnCode] }}
              </template>
            </template></el-table-column>
        </template>
        <el-table-column
          label="操作"
          width="70px"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <div>
              <el-popover
                :ref="`popover-${scope.$index}`"
                placement="bottom-end"
                popper-class="tableOp"
                width="160"
                :popper-options="{
                    boundariesElement: 'opBox',
                    removeOnDestroy: true,
                  }"
                trigger="click"
              >
                <div class="operation">
                  <ul>
                    <li @click="handleClick(scope.row)">
                      查看
                    </li>
                    <li v-show="scope.row.getProductBillState === 0" v-permission="'MenuCode2-3-2-2'" @click="handleUpdata(scope.row)">
                      修改
                    </li>
                  </ul>
                  <ul>
                    <li v-show="scope.row.getProductBillState === 0" v-permission="'MenuCode2-3-2-3'" @click="handleConfirm(scope.row)">
                      确认
                    </li>
                    <li v-show="scope.row.getProductBillState === 1 && scope.row.outStockState === 0 " v-permission="'MenuCode2-3-2-6'" @click="handleDone(scope.row)">
                      作废
                    </li>
                    <li v-show="scope.row.getProductBillState === 2 " v-permission="'MenuCode2-3-2-5'" @click="handleCopy(scope.row)">
                      复制
                    </li>
                  </ul>
                  <ul>
                    <li v-show="scope.row.getProductBillState === 0" v-permission="'MenuCode2-3-2-4'" @click="handleDelete(scope.row)">
                      删除
                    </li>
                  </ul>
                </div>
                <div slot="reference" class="opBox pointer">
                  <span class="el-icon-more c_3F61F1" />
                </div>
              </el-popover>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div v-if="tableHead.length == 0" class="p16">
        <el-skeleton :rows="6" animated />
      </div>
    </div> -->
    <!-- 人员寻找弹框   -->
    <per-redio-dialog :per-visible.sync="isperShow" @getEmployee="getEmployee" />
    <el-dialog
      :title="tname"
      :visible.sync="isAddProduct"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="85%"
      @close="closeDialog"
      @open="openCp"
    >
      <div class="dialogDody">
        <div class="subTip">
          <span class="mr15"><span class="mr5">领料单号：</span>{{ ProductForm.getProductBillNo || '系统自动生成' }}</span>
          <span class="mr15"><span class="mr5">创建日期：</span>{{ ProductForm.createDate || dayjs().format('YYYY-MM-DD') }}</span>
          <span class="mr15"><span class="mr5">创建人员：</span>{{ opsid != 1 ? ProductForm.createPersonName:name }}</span>
        </div>
        <div class="addWuliaoBox">
          <el-form
            ref="ProductForm"
            :model="ProductForm"
            :rules="rules"
            label-width="110px"
            label-position="left"
            class="dialogForm dialogInlineForm"
            :disabled="canDiable"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="领料类型" prop="purchaseType">
                  <el-input v-model="bcptype" placeholder="半成品领料" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关联单据">
                  <div class="flex flex_center">
                    <div class="flex1">
                      <el-input v-model="ProductForm.produceTaskBillNo" placeholder="选择生产单" size="mini" disabled />
                    </div>
                    <div class="ml10 ">
                      <selectProductOrder />
                    </div>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="领料人员" prop="getProductPersonName">
                  <div class="flex flex_center">
                    <div class="flex1">
                      <el-input v-model="ProductForm.getProductPersonName" size="mini" placeholder="请选择人员">
                        <el-button slot="append" icon="el-icon-user" @click="isperShow=true" />
                      </el-input>
                    </div>
                  </div></el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="领料设备" prop="equipmentNo">
                  <el-select
                        filterable
                    v-model="ProductForm.equipmentNo"
                    placeholder="领料设备"
                    size="mini"
                    filterable
                    @change="supplierChange">
                    <el-option
                      v-for="item in equipmentList"
                      :key="item.equipmentNo"
                      :label="item.equipmentName"
                      :value="item.equipmentNo"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="客户单号" prop="customerBillNo">
                  <el-input v-model="ProductForm.customerBillNo" placeholder="客户单号" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="产品名称" prop="orderProductName">
                  <el-input v-model="ProductForm.orderProductName" placeholder="产品名称" size="mini" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="版本版面" prop="productVersion" v-if="this.opsid === 2">
                  <el-input v-model="ProductForm.productVersion" placeholder="版本版面" size="mini" disabled />
                </el-form-item>
                <el-form-item label="版本版面" prop="orderProductVersion" v-else>
                  <el-input v-model="ProductForm.productVersion" placeholder="版本版面" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="订单单号" prop="xieYiShuHao">
                  <el-input v-model="ProductForm.xieYiShuHao" placeholder="订单单号" size="mini" disabled />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="产品编码" prop="productCode">
                  <el-input v-model="ProductForm.productCode" placeholder="产品编码" size="mini" disabled />
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-form-item label="领料备注" class="inlineText">
              <el-input v-model="ProductForm.getProductRemark" type="textarea" :rows="1" placeholder="领料备注" size="mini" clearable />
            </el-form-item>
          </el-form>
          <div class="tableBox">
            <div class="tt flex flex_between">
              <span class="fw">领料明细</span>
              <span v-if="!canDiable" class="c_3F61F1 mr15 pointer" @click="isSemidialog = true"><i class="el-icon-plus mr5" /> 新增</span>
            </div>
            <div ref="bigdialogTable" class="bigdialogTbCon">
              <el-table
                :data="ProductForm.mxDataList"
                border
                style="width: 100%"
              >
                <el-table-column
                  prop="productNo"
                  label="成品编号"
                  width="120"
                />
                <el-table-column
                  label="成品类型"
                  prop="productCategory"
                  show-overflow-tooltip
                  min-width="100"
                />
                <el-table-column
                  label="所属客户"
                  prop="customerName"
                  show-overflow-tooltip
                  min-width="100"
                />
                <el-table-column
                  label="半成品名称"
                  prop="productName"
                  min-width="100"
                />
                <el-table-column
                  label="包含工艺"
                  prop="finishedCraftNames"
                  min-width="100"
                />
                <el-table-column
                  label="库存数量"
                  prop="stockQuantity"
                  min-width="110"
                >
                </el-table-column>
                <el-table-column
                  label="领料数量"
                  prop="applyGetQuantity"
                  show-overflow-tooltip
                  min-width="90"
                >         <template slot-scope="{row}">
                  <el-input
                    v-model="row.applyGetQuantity"
                    :disabled="canDiable"
                    placeholder="请输入"
                    size="mini"
                    onkeyup="value=value.replace(/[^\d]/g,'')"
                  />
                </template>
                </el-table-column>
                <el-table-column
                  label="单位"
                  prop="productUnit"
                  min-width="80"
                />
                <el-table-column
                  label="备注"
                  show-overflow-tooltip
                  min-width="150"
                  prop="getProductRemark"
                >
                  <template slot-scope="{row}">
                    <el-input v-model="row.getProductRemark" :disabled="canDiable" placeholder="请输入" size="mini" />
                  </template>
                </el-table-column>
                <el-table-column
                  v-if="!canDiable"
                  label="操作"
                  fixed="right"
                  show-overflow-tooltip
                  min-width="80"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-tooltip class="item" effect="dark" content="删除" placement="right-start">
                      <span class="pointer" @click="purchaseDelete(scope.$index)"><i class="el-icon-delete" /></span>
                    </el-tooltip>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="opsid === 2" size="mini" @click="printLL">打印领料单</el-button>
        <el-button size="mini" @click="isAddProduct=false">取 消</el-button>
        <!-- 新增       -->
        <el-button
          v-if="opsid !== 2"
          :loading="addProductLoading"
          :disabled="addProductLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="savell"
        >{{ btm }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      append-to-body
      title="选择半成品"
      :visible.sync="isSemidialog"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="70%"
      @close="closeSemiDialog"
      @open="openmater"
    >
      <div class="dialogDody marDialog flex flex_column">
        <div class="btnCon flex flex_end">
          <!--      搜索框-->
          <div class="search">
            <el-input
              v-model="SemiSearch.likeWords"
              placeholder="输入关键字"
              size="small"
            >
              <el-button
                slot="append"
                :loading="marLoading"
                type="primary"
                icon="el-icon-search"
                :disabled="marLoading"
                element-loading-spinner="el-icon-loading"
                @click="openmater"
              >
                搜索
              </el-button>
            </el-input>
          </div>
        </div>
        <!-- 表格区域       -->
        <div class="tableCon not">
          <el-table
            :data="materialList"
            border
            height="300"
            style="width: 100%"
            @selection-change="handleSelectionChange"
          >
            <el-table-column prop="selection" width="55">
              <el-table-column
                type="selection"
                width="55"
              />
              <el-table-column prop="productNo" label="半成品编号" />
              <el-table-column prop="productName" label="成品名称" />
              <el-table-column prop="productTypeName" label="成品类型" />
              <el-table-column prop="customerName" label="所属客户" />
              <el-table-column prop="finishedCraftNames" label="包含工艺" />
              <el-table-column prop="stockQuantity" label="库存数量" />
              <el-table-column prop="productUnit" label="单位" />
            </el-table-column></el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isSemidialog = false">取 消</el-button>
        <!-- 选择订单 -->
        <el-button
          v-loading="addLoading"
          :disabled="addLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="saveColorManuscript"
        >
          确定</el-button>
      </div>
    </el-dialog>
    <!-- 原因   -->
    <el-dialog
      title="作废原因"
      :visible.sync="isNopassshow"
      :close-on-click-modal="false"
      custom-class="comDialog"
      width="40%"
      @close="closePassDialog"
    >
      <div class="dialogDody">
        <el-form ref="passForm" :model="passForm" class="dialogForm">
          <el-form-item class="mt12">
            <el-input
              v-model="passForm.cancelReason"
              prop="cancelReason"
              type="textarea"
              placeholder="请输入内容"
              :autosize="{ minRows: 6 }"
              size="mini"
            />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isNopassshow = false">取 消</el-button>
        <el-button
          :disabled="addLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="passSave"
        >提交</el-button>
      </span>
    </el-dialog>
    <printBcpLLT :product-from="prinftMass" />
  </div>
</template>
<script>
import { arraySort } from '@/utils'
import HeadSeting from '@/components/HeadSeting'
import Pagination from '@/components/Pagination'
import perRedioDialog from '@/components/perDialogRedio'
import selectProductOrder from '@/components/selectProductOrder'
import SelectSCorder from '@/components/selectSCorder'
import printBcpLLT from './printBcpLLT.vue'
import screec from "@/components/screen";
import naTable from "@/components/naTable";
import { mapGetters } from 'vuex'

export default {
  name: 'Materiel',
  components: { Pagination, HeadSeting, perRedioDialog, selectProductOrder, SelectSCorder, printBcpLLT,screec,naTable },
  data() {
    return {
      ops: 'add', // 操作、新建，修改，查看
      opsid: 1, // 3 确定 1 新建， 4 修改， 2 查看
      bcptype: '半成品领料',
      tableHeight: null, // 表格最大高度
      showOrder: false,
      isSeeMaterriel: false, // 查看弹框是否打开
      isAddMaterriel: false, // 新建弹框是否打开
      addMaterrielLoading: false, // 新建保存加载
      searchLoading: false, // 搜索加载效果
      allMaterirls: [], // 全部数据列表
      colorState: null,
      addLoading: false,
      selectRow: null,
      isNopassshow: false,
      equipmentList: [],
      passForm: {
        cancelReason: ''
      },
      prinftMass: {
      },
      // 表格操作
      ProductForm: {
        getProductType: 1,
        getProductPersonName: '',
        equipmentNo: '',
        mxDataList: []
      },
      // 搜索条件
      search: {
        QueryDataBaseFiled:'',
        pageIndex: 1,
        pageSize: 30,
        likeWords: ''
      },

      tableData: {
          headId: 'head', //表头列显隐组件所需ID-避免多个页面id重复问题
          tableId: 'getProductID', //表格列表key,也就是一条数据的唯一标识
          senior: false, //高级搜索是否显示
          addPermission: 'MenuCode2-3-2-1', //新建按钮权限
          disableWord: '', //是否禁用显示的字段
          disableStatus: '', //判断未禁用的状态值
          //表格按钮
          operationBtn: [{
              title: '查看',
              methodsName: 'handleClick',
            }, {
              title: '编辑',
              methodsName: 'handleUpdata',
              permission: "MenuCode2-3-2-2",
              hideCondition: { //按钮显隐条件
                prop: 'getProductBillState', //控制显隐的状态字段
                show: [ //有哪些状态可以使用
                  0
                ],
              },
            },
            {
              title: '确定',
              methodsName: 'handleConfirm',
              permission: "MenuCode2-3-2-3",
              hideCondition: { //按钮显隐条件
                prop: 'getProductBillState', //控制显隐的状态字段
                show: [ //有哪些状态可以使用
                  0
                ],
              },
            },
            {
              title: '作废',
              methodsName: 'handleDone',
              permission: "MenuCode2-3-2-6",
              hideCondition: { //按钮显隐条件
                prop: 'isViod', //控制显隐的状态字段
                show: [ //有哪些状态可以使用
                  1
                ],
              },
            },
            {
              title: '复制',
              methodsName: 'handleCopy',
              permission: "MenuCode2-3-2-5",
              hideCondition: { //按钮显隐条件
                prop: 'getProductBillState', //控制显隐的状态字段
                show: [ //有哪些状态可以使用
                  2
                ],
              },
            },
            {
              title: '删除',
              methodsName: 'handleDelete',
              permission: "MenuCode2-3-2-4",
              hideCondition: { //按钮显隐条件
                prop: 'getProductBillState', //控制显隐的状态字段
                show: [ //有哪些状态可以使用
                  0
                ],
              },
            },
          ],
          //表格内容
          tbody: [],
          //表格表头
          thead: [],
        },



      total: 0, // 总条数
      tableHead: [], // 表格表头
      addProductLoading: false,
      isAddProduct: false,
      isperShow: false,
      isSemidialog: false,
      multipleSelection: [],
      purchaseInfoDatas: [{}],
      allSupliers: [],
      purchaseTypes: [{
        dicValueID: 0,
        dicValueDesc: '生产领料',
        dicValueCode: 1
      }, {
        dicValueID: 1,
        dicValueDesc: '生产补料',
        dicValueCode: 2
      }],
      SemiSearch: [],
      materialList: [],
      marLoading: false,
      canDiable: false,
      rules: {
        getProductPersonName: [
          { required: true, message: '请选择人员', trigger: 'change' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters(['name', 'userInfo']),
    btm() {
      if (this.opsid === 3) {
        return '确认'
      } else {
        return '保存'
      }
    },
    tname() {
      if (this.opsid === 1) {
        return '新建半成品领料单'
      } else if (this.opsid === 2) {
        return '查看半成品领料单'
      } else if (this.opsid === 3) {
        return '确定半成品领料单'
      } else if (this.opsid === 4) {
        return '修改半成品领料单'
      } else {
        return '复制半成品领料单'
      }
    }
  },
  created() {
    //  所有列表数据
    this.getAllMaterils()
    // 表格得表头
    this.getTableHead()
    if (this.$route.query.openADD) {
      const row = this.$route.query.item
      this.ops = 'add'
      this.isAddProduct = true
      this.ProductForm.produceTaskBillNo = row.produceTaskBillNo
      this.ProductForm.saleOrderNo = row.saleOrderNo
      this.openCp()
    }
  },
  mounted() {
  },
  updated() {
  },
  methods: {

    printLL() {
      const { mxDataList, ...basedata } = this.ProductForm
      this.prinftMass = {
        mxDataList: mxDataList,
        basedata: basedata
      }
      var printHtml = document.getElementById('print-iframe-ll').innerHTML
      var wind = window.open('', 'newwindow', ' top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no')
      wind.document.body.innerHTML = printHtml
      wind.print()
    },

    closePassDialog() {
      this.passForm.cancelReason = ''
      this.selectRow = null
    },

    checkProductList(row) {
      this.opsid = 2
      this.canDiable = true
      this.getDetail(row)
      // this.$router.push({
      //   path: '/business/orderDetail', // 跳转的路径
      //   query: {
      //     tabIndex: 4,
      //     saleOrderNo: row.saleOrderNo,
      //     lltype: '0'
      //   }
      // })
    },
    // 新建点击事件
    newAddClick() {
      this.ops = 'add'
      // this.isAddProduct = true
      this.opsid = 1
      this.showOrder = true
      this.canDiable = false
      this.ProductForm.getProductPersonName = this.userInfo.employeeName
      this.ProductForm.getProductPerson = this.userInfo.employeeCode
    },
    handleClick(row) {
      this.opsid = 2
      this.canDiable = true
      this.getDetail(row)
    },
    handleConfirm(row) {
      this.opsid = 3
      this.canDiable = true
      this.getDetail(row)
    },
    handleDone(row) {
      this.selectRow = row
      this.isNopassshow = true
    },
    handleCopy(row) {
      this.opsid = 5
      // this.getDetail(row)
      this.openCp()
      this.canDiable = false
      const _data = {
        getProductID: row.getProductID,
        getProductBillNo: row.getProductBillNo
      }
      this.$api.product.GetSemiFinishedProductBillDetail(_data).then((res) => {
        this.equipmentList.push({
          equipmentName: res.equipmentName,
          equipmentNo: res.equipmentNo
        })

        delete res.baseData.getProductID
        delete res.baseData.getProductBillNo
        this.ProductForm = res.baseData
        this.ProductForm.mxDataList = res.mxDataList
        this.isAddProduct = true
      })
    },
    handleUpdata(row) {
      this.opsid = 4
      this.canDiable = false
      this.getDetail(row)
    },
    passSave() {
      const _data = {
        getProductID: this.selectRow.getProductID,
        cancelReason: this.passForm.cancelReason
      }
      this.$api.product.CancelGetSemiFinishedProductBill(_data).then(() => {
        this.getAllMaterils()
        this.isNopassshow = false
        this.addLoading = false
        this.$message({
          message: '作废成功',
          type: 'success'
        })
      }).catch(() => {
      })
    },
    handleDelete(row) {
      const _data = {
        getProductID: row.getProductID
      }
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$api.product.DeleteGetSemiFinishedProductBill(_data).then(() => {
          this.getAllMaterils()
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        }).catch(() => {
        })
      })
    },
    getDetail(row) {
      const _data = {
        getProductID: row.getProductID,
        getProductBillNo: row.getProductBillNo
      }
      this.$api.product.GetSemiFinishedProductBillDetail(_data).then((res) => {
        this.equipmentList.push({
          equipmentName: res.equipmentName,
          equipmentNo: res.equipmentNo
        })
        this.ProductForm = res.baseData
        this.ProductForm.productVersion = res.baseData.printingSurface+res.baseData.productVersion
        this.ProductForm.mxDataList = res.mxDataList
        this.prinftMass = res
        this.isAddProduct = true
      })
    },
    selectCurrentRow(row) {
      this.ops = 'add'
      this.isAddProduct = true
      this.ProductForm.produceTaskBillNo = row.produceTaskBillNo
      this.ProductForm.saleOrderNo = row.saleOrderNo
      this.ProductForm.productCode = row.productCode
      this.ProductForm.customerBillNo = row.customerBillNo
      this.ProductForm.orderProductName = row.orderProductName
      this.ProductForm.createPersonName = row.createPersonName
      this.ProductForm.productVersion = row.printingSurface+row.orderProductVersion
      this.ProductForm.xieYiShuHao = row.xieYiShuHao
      console.log(this.ProductForm.productVersion)
    },
    purchaseDelete(index) {
      this.ProductForm.mxDataList.splice(index, 1)
    },
    // 选择物料
    openmater() {
      const _data = {
        isPublic: -1,
        likeWords: ''
      }
      this.$api.product.GetMatchSemiFinishedProductList(_data).then((res) => {
        res.forEach(v => {
          v.goodsCategoryName = v.categoryName
          v.planUseQuantity = v.planMaterialQuantity
        })
        this.materialList = res
      })
    },
    openCp() {
      const _data = {
        produceTaskBillNo: this.ProductForm.produceTaskBillNo,
        likeWords: ''
      }
      this.$api.product.GetProduceTaskEquipmentList(_data).then((res) => {
        this.equipmentList = res
        if (res && res.length) {
          this.ProductForm.equipmentNo = res[0].equipmentNo
        }
      })
    },
    savell() {
      if (this.opsid === 3) {
        const _data3 = {
          getProductID: this.ProductForm.getProductID
        }
        this.$api.product.SureGetSemiFinishedProductBill(_data3).then(() => {
          this.addProductLoading = false
          this.isAddProduct = false
          this.getAllMaterils()
          this.$message({
            message: '确认成功',
            type: 'success'
          })
        }).catch(() => {
          this.addProductLoading = false
        })
      } else if (this.opsid === 4) {
        if(this.ProductForm.mxDataList.length<1){
          this.$message.warning('请选择物料明细')
          return
        }
        const parmas = this.ProductForm
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true
            this.$api.product.UpdateGetSemiFinishedProductBill(parmas).then(() => {
              this.addProductLoading = false
              this.isAddProduct = false
              this.getAllMaterils()
              this.$message({
                message: '修改成功',
                type: 'success'
              })
            }).catch(() => {
              this.addProductLoading = false
            })
          }
        })
      } else {
        if(this.ProductForm.mxDataList.length<1){
          this.$message.warning('请选择物料明细')
          return
        }
        const parmas = this.ProductForm
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true
            this.$api.product.CreateGetSemiFinishedProductBill(parmas).then(() => {
              this.addProductLoading = false
              this.isAddProduct = false
              this.getAllMaterils()
              this.$message({
                message: '保存成功',
                type: 'success'
              })
            }).catch(() => {
              this.addProductLoading = false
            })
          }
        })
      }
    },

    // 得到申请人员
    getEmployee(val) {
      this.ProductForm.getProductPersonName = val.employeeName
      this.ProductForm.getProductPerson = val.employeeCode
    },
    supplierChange(val) {
      this.materSearch.supplierCode = val
      this.purchaseInfoDatas = []
    },
    closeSemiDialog() {
      this.isSemidialog = false
    },
    handleSelectionChange(val) {
      val.forEach(res => {
        res.productCategory = res.productTypeName
        // res.planUseQuantity = res.planMaterialQuantity
      })
      this.multipleSelection = val
    },
    saveColorManuscript() {
      if(this.multipleSelection.length<1){
        this.$message.warning('请选择半成品')
        return
      }
      const array = JSON.parse(JSON.stringify(this.ProductForm.mxDataList))
      const arr = JSON.parse(JSON.stringify(this.multipleSelection))
      arr.forEach(item => {
        item.applyGetQuantity = item.planUseQuantity
        item.getMaterialRemark = ''
        item.sumStockQuantity = item.stockQuantity
      })
      this.ProductForm.mxDataList = arr.reduce((result, item) => {
        const val = result.some(({ productNo }) => productNo === item.productNo)
        if (!val) {
          result.push(item)
        }
        return result
      }, array)
      this.closeSemiDialog()
    },
    // 详情
    getMaterielInfo(id) {},
    // 保存表头样式变化
    saveHead(newArray) {
      const parmas = newArray
      setTimeout(() => {
        this.$api.common.saveTableStyle(parmas).then(() => {})
      }, 300)
    },
    // 保存表头列宽度
    surverWidth(newWidth, oldWidth, column) {
      setTimeout(() => {
        const heads = [...this.tableHead]
        heads.forEach(item => {
          if (item.columnCode === column.property) {
            item.columnWidth = column.width
            return
          }
        })
        this.saveHead(heads)
      }, 100)
    },
    // ，清除所有查询条件
    Refresh() {
      this.search = this.$options.data().search
      this.getAllMaterils()
    },
    // 获取表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.semifinishedproductllbilllist
      }
      this.$api.common.getAllTableHead(parmas).then((res) => {
        console.log(res)
        res.sort(arraySort('columnSort'))
        this.tableData.thead = res;
      })
    },
    // 所有列表数据
    getAllMaterils() {
      const parmas = this.search
      this.searchLoading = true
      this.$api.product
        .PageQueryGetSemiFinishedProductBills(parmas)
        .then((res) => {
          this.allMaterirls = res.list
          this.tableData.tbody = res.list;
            this.search.total = res.totalCount;
          this.allMaterirls.forEach((item)=>{
            item.isViod = 0;  //作废
            if(item.getProductBillState === 1 && item.outStockState === 0){
              item.isViod = 1
            }
            for(let i in item){
              if(!item[i] && item[i] !== 0){
                item[i] = '--'
              }
            }
          })
          this.total = res.totalCount
          this.searchLoading = false
        })
        .catch(() => {
          this.searchLoading = false
        })
    },
    // 新建弹框关闭事件
    closeDialog() {
      if (this.$refs.ProductForm) {
        this.$refs.ProductForm.resetFields()
      }
      this.ProductForm = this.$options.data().ProductForm
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  height: 100%;
}
.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
}
.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
}

.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}

</style>
